<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./vue.js"></script>
    <script src="./axios.min.js"></script>

    <style>
        li {
            list-style: none;
        }

        .divBox {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin: 10px 0;
        }

        .red {
            color: red;
        }

        .green {
            color: green;
        }
    </style>
</head>

<body>
    <!-- 
    cmtcount:58
id:1
img:"/images/0.webp"
source:"新京报经济新闻"
tags:"三大运营商,中国移动,5G商用"
time:"2019-10-28T03:50:28.000Z"
title:"5G商用在即，三大运营商营收持续下降" -->

    <div id="app">

        <ul>
            <li v-for='(item,index) in  newsList' :key='item.id'>
                <img :src="'http://www.liulongbin.top:3006'+item.img" alt="">
                <h2 :class="index % 2== 0 ? 'red':'green' "> {{item.title}}</h2>
                <p> {{item.source}}</p>
                <div>

                    <span> {{item.tags}}</span>
                </div>
                <div class="divBox">
                    <span> {{item.cmtcount}} 条评论</span>
                    <span> {{item.time}}</span>
                </div>



            </li>
        </ul>
    </div>

    <script>
        //创建Vue实例,得到 ViewModel
        var vm = new Vue({
            el: '#app',
            data: {

                newsList: []
            },
            methods: {
                getNewsList() {
                    axios.get('http://www.liulongbin.top:3006/api/news').then(res => {
                        this.newsList = res.data.data
                    })
                }

            },
            created() {
                // axios.get('http://www.liulongbin.top:3006/api/news').then(res=>{
                //   this.newsList=  res.data.data
                // })
                this.getNewsList()

            },
            mounted() {
                // this.getNewsList()


            }
        });
    </script>
</body>

</html>